Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: add database indices #2192

Merged
merged 1 commit into from
Oct 4, 2024
Merged

perf: add database indices #2192

merged 1 commit into from
Oct 4, 2024

Conversation

chronark
Copy link
Collaborator

@chronark chronark commented Oct 4, 2024

Summary by CodeRabbit

  • Performance Improvements
    • Enhanced query performance for audit logs with the addition of new indexes on key fields.
    • Optimizations include indexes for bucketId, event, actorId, and time in the audit_log table, as well as an index for auditLogId in the audit_log_target table.

Copy link

vercel bot commented Oct 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 7:17pm
planetfall ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 7:17pm
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 7:17pm
unkey-engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 7:17pm
workflows ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 7:17pm
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 7:17pm

Copy link

changeset-bot bot commented Oct 4, 2024

⚠️ No Changeset found

Latest commit: 6bcc69b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request involve modifications to the audit_logs.ts file, specifically the addition of several new indexes to the audit_log and audit_log_target tables. These indexes are designed to enhance query performance for specific fields, including bucketId, event, actorId, and time in the audit_log table, and auditLogId in the audit_log_target table. No other structural changes or functional modifications were made.

Changes

File Change Summary
internal/db/src/schema/audit_logs.ts Added five new indexes to audit_log: bucketId, event, actorId, time; added one index to audit_log_target: auditLogId.

Possibly related PRs

  • refactor: query audit logs from planetscale #2181: The changes in this PR involve modifications to the retrieval of audit logs, which may interact with the newly added indexes in the audit_logs.ts file to optimize query performance for the fields being filtered, such as event, time, and actorId.

Suggested reviewers

  • mcstepp
  • perkinsjr

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

github-actions bot commented Oct 4, 2024

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
internal/db/src/schema/audit_logs.ts (1)

122-122: LGTM: Index on auditLogId added with a minor naming suggestion.

The addition of an index on auditLogId in the audit_log_target table is a good performance optimization. It will improve the efficiency of joins between audit_log_target and audit_log tables.

However, for consistency with the naming convention used in other indexes, consider renaming the index to "audit_log_id_idx".

Suggested change:

- auditLog: index("audit_log_id").on(table.auditLogId),
+ auditLog: index("audit_log_id_idx").on(table.auditLogId),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bfcb46d and 6bcc69b.

📒 Files selected for processing (1)
  • internal/db/src/schema/audit_logs.ts (2 hunks)
🔇 Additional comments (5)
internal/db/src/schema/audit_logs.ts (5)

81-81: LGTM: Index on bucketId added.

The addition of this index on bucketId is a good performance optimization. It will improve query performance when filtering or joining on the bucketId column, which is likely a common operation for audit logs.


82-82: LGTM: Index on event added.

Adding an index on the event column is beneficial for performance. It will speed up queries that filter or sort by event type, which is likely a common operation in audit log analysis.


83-83: LGTM: Index on actorId added.

The addition of an index on actorId is a good performance optimization. It will improve query performance when filtering or joining on the actorId column, which is useful for tracking actions by specific actors in the audit logs.


84-84: LGTM: Crucial index on time added.

The addition of an index on the time column is an excellent performance optimization. Time-based queries are extremely common in audit log systems, and this index will significantly improve the performance of filtering, sorting, and range queries based on timestamps. This is likely to be one of the most frequently used indexes in this table.


81-84: Summary: Excellent performance optimizations with database indices.

The changes in this file successfully implement the PR objective of adding database indices for performance improvement. The new indexes on bucketId, event, actorId, and time in the audit_log table, and auditLogId in the audit_log_target table, are well-chosen and will likely significantly improve query performance for common operations on audit logs.

These optimizations follow best practices for database performance tuning and are focused solely on the stated objective without introducing unrelated changes. Great job on improving the efficiency of the audit log system!

Also applies to: 122-122

@chronark chronark added this pull request to the merge queue Oct 4, 2024
Merged via the queue into main with commit a54a2e2 Oct 4, 2024
29 checks passed
@chronark chronark deleted the auditlog-incides branch October 4, 2024 19:22
AkshayBandi027 pushed a commit to AkshayBandi027/unkey that referenced this pull request Oct 5, 2024
github-merge-queue bot pushed a commit that referenced this pull request Oct 5, 2024
* feat/mobile-sidbar-sync-with-desktop

* fix(billing): add missing subscription fields and audit logging to upgrade flow (#2179)

* fix(billing): add missing subscription fields and audit logging to upgrade flow

* fix context properties

* refactor: query audit logs from planetscale (#2181)

* refactor: query audit logs from planetscale

* fix: sort logs

* [autofix.ci] apply automated fixes

* chore: remove csv export

* Update apps/dashboard/app/(app)/audit/[bucket]/page.tsx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fmt: add comma

* ci: remove wrong lint command

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* chore: Unkey PDF Viewer template [SIDE QUEST] (#2191)

* chore: Unkey PDF Viewer template

* feat: add template

---------

Co-authored-by: chronark <dev@chronark.com>

* perf: add database indices (#2192)

* fix: add header again

* docs: Removing pnpm test:routes (#2184)

* fix: revalidate /apis after creating new API (#2183)

* fix: revalidate /apis after creating new API key

* fix: show success message after revalidate suceeds

* fix: revalidate cache before routing

* chore(deps-dev): bump @types/react-dom from 18.2.25 to 18.3.0 (#2187)

Bumps [@types/react-dom](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react-dom) from 18.2.25 to 18.3.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react-dom)

---
updated-dependencies:
- dependency-name: "@types/react-dom"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Refactor/workspace-navigation

* ran fmt

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Meg Stepp <mcstepp@users.noreply.github.com>
Co-authored-by: Andreas Thomas <dev@chronark.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Nazar Poshtarenko <32395926+unrenamed@users.noreply.github.com>
Co-authored-by: Harsh Shrikant Bhat <90265455+harshsbhat@users.noreply.github.com>
Co-authored-by: Gerald Maboshe <maboshegerald1@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
harshsbhat added a commit to harshsbhat/unkey that referenced this pull request Oct 5, 2024
* feat/mobile-sidbar-sync-with-desktop

* fix(billing): add missing subscription fields and audit logging to upgrade flow (unkeyed#2179)

* fix(billing): add missing subscription fields and audit logging to upgrade flow

* fix context properties

* refactor: query audit logs from planetscale (unkeyed#2181)

* refactor: query audit logs from planetscale

* fix: sort logs

* [autofix.ci] apply automated fixes

* chore: remove csv export

* Update apps/dashboard/app/(app)/audit/[bucket]/page.tsx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fmt: add comma

* ci: remove wrong lint command

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* chore: Unkey PDF Viewer template [SIDE QUEST] (unkeyed#2191)

* chore: Unkey PDF Viewer template

* feat: add template

---------

Co-authored-by: chronark <dev@chronark.com>

* perf: add database indices (unkeyed#2192)

* fix: add header again

* docs: Removing pnpm test:routes (unkeyed#2184)

* fix: revalidate /apis after creating new API (unkeyed#2183)

* fix: revalidate /apis after creating new API key

* fix: show success message after revalidate suceeds

* fix: revalidate cache before routing

* chore(deps-dev): bump @types/react-dom from 18.2.25 to 18.3.0 (unkeyed#2187)

Bumps [@types/react-dom](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react-dom) from 18.2.25 to 18.3.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react-dom)

---
updated-dependencies:
- dependency-name: "@types/react-dom"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Refactor/workspace-navigation

* ran fmt

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Meg Stepp <mcstepp@users.noreply.github.com>
Co-authored-by: Andreas Thomas <dev@chronark.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Nazar Poshtarenko <32395926+unrenamed@users.noreply.github.com>
Co-authored-by: Harsh Shrikant Bhat <90265455+harshsbhat@users.noreply.github.com>
Co-authored-by: Gerald Maboshe <maboshegerald1@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
github-merge-queue bot pushed a commit that referenced this pull request Oct 5, 2024
* Add default bytes and prefix

* adding bytes and prefix columns in harness

* fmt

* Await

* Resolved changes

* typo

* Capital and Extra bracket

* [autofix.ci] apply automated fixes

* feat: mobile-sidbar-sync-with-desktop (#2180)

* feat/mobile-sidbar-sync-with-desktop

* fix(billing): add missing subscription fields and audit logging to upgrade flow (#2179)

* fix(billing): add missing subscription fields and audit logging to upgrade flow

* fix context properties

* refactor: query audit logs from planetscale (#2181)

* refactor: query audit logs from planetscale

* fix: sort logs

* [autofix.ci] apply automated fixes

* chore: remove csv export

* Update apps/dashboard/app/(app)/audit/[bucket]/page.tsx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fmt: add comma

* ci: remove wrong lint command

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* chore: Unkey PDF Viewer template [SIDE QUEST] (#2191)

* chore: Unkey PDF Viewer template

* feat: add template

---------

Co-authored-by: chronark <dev@chronark.com>

* perf: add database indices (#2192)

* fix: add header again

* docs: Removing pnpm test:routes (#2184)

* fix: revalidate /apis after creating new API (#2183)

* fix: revalidate /apis after creating new API key

* fix: show success message after revalidate suceeds

* fix: revalidate cache before routing

* chore(deps-dev): bump @types/react-dom from 18.2.25 to 18.3.0 (#2187)

Bumps [@types/react-dom](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react-dom) from 18.2.25 to 18.3.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react-dom)

---
updated-dependencies:
- dependency-name: "@types/react-dom"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Refactor/workspace-navigation

* ran fmt

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Meg Stepp <mcstepp@users.noreply.github.com>
Co-authored-by: Andreas Thomas <dev@chronark.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Nazar Poshtarenko <32395926+unrenamed@users.noreply.github.com>
Co-authored-by: Harsh Shrikant Bhat <90265455+harshsbhat@users.noreply.github.com>
Co-authored-by: Gerald Maboshe <maboshegerald1@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix: update go sdk code examples to the current sdk version (#2200)

* fix: update go sdk code examples to the current sdk version

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Andreas Thomas <dev@chronark.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Akshay <100031493+AkshayBandi027@users.noreply.github.com>
Co-authored-by: Meg Stepp <mcstepp@users.noreply.github.com>
Co-authored-by: Andreas Thomas <dev@chronark.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Nazar Poshtarenko <32395926+unrenamed@users.noreply.github.com>
Co-authored-by: Gerald Maboshe <maboshegerald1@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Oct 8, 2024
18 tasks
mcstepp pushed a commit that referenced this pull request Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants